<template>
  <div>
    <!-- 角色管理 -->

    <!-- 面包屑导航 -->
    <Crumbs></Crumbs>

    <button class="roleBtn" @click="role">添加角色</button>
    <div class="store_list">
      <div class="storeAddList">
        <el-table :data="tableData" border style="width: 70%">
          <el-table-column fixed prop="rolename" label="角色名称" width="200"> </el-table-column>
          <el-table-column prop="jurisdiction" label="角色权限" width="200"> </el-table-column>
          <el-table-column fixed="right" label="操作">
            <template style="display: flex; justify-content: space-around" slot-scope="scope">
              <el-button type="text" size="small" @click="deleteBtn(scope.row)">删除</el-button>
              <el-button type="text" size="small" @click="modifyBtn(scope.row)">修改</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
  </div>
</template>

<script>
import { getXdeleteroleAdmin, getXroleAdmin } from '../../api'
import Crumbs from './Crumbs.vue'
export default {
  components: { Crumbs },
  data() {
    return {
      tableData: [],
    }
  },
  methods: {
    //封装
    fn() {
      getXroleAdmin().then((res) => {
        // console.log(res);
        this.tableData = res.data
      })
    },
    role() {
      this.$router.push('/addRole')
    },

    //删除
    deleteBtn(row) {
      this.$confirm('是否删除该角色?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          this.$message({
            type: 'success',
            message: '删除成功!',
          })
          getXdeleteroleAdmin(row).then((res) => {
            console.log(res)
            this.fn()
          })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除',
          })
        })
    },
    //修改
    modifyBtn(row) {
      this.$router.push({
        path: '/clerkRole',
        name: 'clerkRole',
        params: {
          list: row,
        },
      })
    },
  },
  created() {
    this.fn()
  },
}
</script>

<style lang="scss" scoped>
.roleBtn {
  width: 100px;
  height: 30px;
  border: none;
  margin: 20px 0px 40px 30px;
  border-radius: 10px;
}
.store_list {
  width: 1000px;
  margin: 0 auto;

  .el-table th.el-table__cell {
    background: lightgray;
  }
}
</style>
